package jspservlet.servlet;

import java.io.IOException;
//import java.io.PrintWriter;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import jspservlet.dao.UserDAO;
import jspservlet.dao.impl.UserDAOImpl;
import jspservlet.vo.User;

public class ModifyPswServelt extends HttpServlet {
	
	public void doGet(HttpServletRequest req,HttpServletResponse res) 
		throws IOException,ServletException{
	}
	
	public void doPost(HttpServletRequest req,HttpServletResponse res) 
			throws IOException,ServletException{
	
		UserDAO dao=new UserDAOImpl();
		HttpSession session=req.getSession();
		User user = new User();
		String username = (String)session.getAttribute("username");
		user.setUsername(req.getParameter(username));

		/**	ServletContext application = this.getServletContext();
		HttpSession session=req.getSession();
		session.setAttribute("username", (String) application.getAttribute("username"));
		User user=new User();
		user.setUsername(application.getAttribute("username").toString()); */

		user.setPassword(req.getParameter("password")); //旧密码
		user.setDob(req.getParameter("password1"));     //新密码。没地存了，存在dob里。
		int flag=0;

		try {
			flag = dao.changePsw(user, session);
		} catch (Exception e) {
			e.printStackTrace();
		} 
	}
}
